//
//  XMGSettingCell.m
//  彩票
//
//  Created by xiaomage on 15/9/24.
//  Copyright © 2015年 xiaomage. All rights reserved.
//

#import "CSWSettingCell.h"

#import "CSWSettingArrowItem.h"
#import "CSWSettingSwitchItem.h"

@interface CSWSettingCell ()

@property (nonatomic, strong) UISwitch *switchView;

@end

@implementation CSWSettingCell

- (UISwitch *)switchView
{
    if (_switchView == nil) {
        UISwitch *switchView = [[UISwitch alloc] init];
        _switchView = switchView;
    }
    return _switchView;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"cell";
    CSWSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }

    return cell;
}
- (void)setItem:(CSWSettingItem *)item
{
    _item = item;
    
    // 设置cell的数据
    [self setUpData];
    
    // 设置辅助视图
    [self setUpAccessory];
   

}
// 设置数据
- (void)setUpData
{
    self.textLabel.text = _item.title;
    self.imageView.image = _item.image;
}

// 设置辅助视图
- (void)setUpAccessory
{
    if ([_item isKindOfClass:[CSWSettingArrowItem class]]) {
        // 显示箭头
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if ([_item isKindOfClass:[CSWSettingSwitchItem class]]){ // 开关
        self.accessoryView = self.switchView;
        
    }else{
        self.accessoryView = nil;
        self.accessoryType = UITableViewCellAccessoryNone;
    }
}
@end
